package com.nut.service.impl;

import com.nut.entity.User;
import com.nut.mapper.UserMapper;
import com.nut.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-04-20 20:10
 * @ Description : User service层实现
 */

@Service
public class UserServiceImpl implements UserService
{
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAllUsers()
    {
        return userMapper.findAll();
    }

    @Override
    public void saveUser(User user)
    {
        userMapper.add(user);
    }

    @Override
    public void deleteUserById(int id)
    {
        userMapper.delete(id);
    }

    @Override
    public void updateUser(User user)
    {
        userMapper.update(user);
    }

    @Override
    public List<User> findByPage(Integer pageNow, Integer rows)
    {
        int start = (pageNow - 1) * rows;
        return userMapper.findByPage(start,rows);
    }

    @Override
    public Long findTotals()
    {
        return userMapper.findTotals();
    }

    @Override
    public User findUserById(int id)
    {
        //查询User
        return userMapper.query(id);

    }
}
